#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/*
 * Zenlayer.com Inc.
 * Copyright (c) 2014-2020 All Rights Reserved.
 */
package ${package}.${artifactId}.config;

import com.xxl.job.${artifactId}.executor.impl.XxlJobSpringExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yangshen
 * @version ${symbol_dollar} Id: XxlJobConfig.java, v 0.1  yangshen Exp ${symbol_dollar}
 * @date 2019-11-13 15:11:05
 */
@Configuration
public class XxlJob2Config {

    private static final Logger logger = LoggerFactory.getLogger(XxlJob2Config.class);

    @Value("${symbol_dollar}{xxljob.enabled:false}")
    private Boolean enabled;

    @Value("${symbol_dollar}{xxl.job.admin.addresses}")
    private String adminAddresses;

    @Value("${symbol_dollar}{xxl.job.executor.appname}")
    private String appName;

    @Value("${symbol_dollar}{xxl.job.executor.ip}")
    private String ip;

    @Value("${symbol_dollar}{xxl.job.executor.port}")
    private int port;

    @Value("${symbol_dollar}{xxl.job.accessToken}")
    private String accessToken;

    @Value("${symbol_dollar}{xxl.job.executor.logPath}")
    private String logPath;

    @Value("${symbol_dollar}{xxl.job.executor.logretentiondays}")
    private int logRetentionDays;

    @Bean(initMethod = "start", destroyMethod = "destroy")
    public XxlJobSpringExecutor xxlJobExecutor() {
        logger.info(">>>>>>>>>>> xxl-job config init.enabled={}", enabled);
        if (!enabled) {
            return null;
        }
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
        xxlJobSpringExecutor.setAppname(appName);
        xxlJobSpringExecutor.setIp(ip);
        xxlJobSpringExecutor.setPort(port);
        xxlJobSpringExecutor.setAccessToken(accessToken);
        xxlJobSpringExecutor.setLogPath(logPath);
        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);


        return xxlJobSpringExecutor;
    }
}
